package com.sysofstudent.service;

import com.sysofstudent.dao.StudentRepository;
import com.sysofstudent.po.Score;
import com.sysofstudent.po.Student;
import com.sysofstudent.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentImpl implements StudentService{

    @Autowired
    private StudentRepository studentRepository;


    @Override
    public Student checkStudent(String number, String password) {

        Student student = studentRepository.findByNumberAndPassword(number, MD5Utils.code(password)) ;
        return student;
    }

    @Override
    public Student findStudent(String number) {
        Student student =studentRepository.findByNumber(number);
        return student;
    }

    @Override
    public List<Student> getStudentList() {
        return studentRepository.findAll();
    }

    @Override
    public Student findStudentById(long id) {

        return studentRepository.findById(id);
    }



    @Override
    public void save(Student student) {
        student.setPassword(MD5Utils.code(student.getPassword()));
        studentRepository.save(student);
    }

    @Override
    public void delete(Long id) {
        studentRepository.deleteById(id);
    }

    @Override
    public void edit(Student student) {
        student.setPassword(MD5Utils.code(student.getPassword()));
        studentRepository.save(student);
    }


}
